﻿Imports System.Data.SqlClient
Imports System.Web
Imports System.Data.OleDb
Public Class CreateUser
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted
        If e.Exception Is Nothing Then

            Response.Redirect("createuser2.aspx")



        End If
    End Sub

    Private Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\CruisesDB.accdb;Persist Security Info=True"
        Dim dt As New DataTable()
        Dim UnameTextBox As TextBox = CType(Me.FormView1.FindControl("UnameTextBox"), TextBox)
        Dim conn As New OleDbConnection(connectionString)


        'SELECT        Uname, UPassword FROM            Users WHERE        (Uname = '1') AND (UPassword = '2')

        Dim sql As String = "select * from Users where Uname='" & UnameTextBox.Text & "'"



        Dim cmd As New OleDbCommand(sql, conn)
        If conn.State = Data.ConnectionState.Closed Then conn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        If dr.HasRows Then
          
            Label1.Text = "This is account had been use, please change the user name"
            Label1.Visible = True
            e.Cancel = True
        End If
        conn.Close()
    End Sub
End Class